package com.etc.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.etc.entity.RFoods;
import com.etc.service.FoodsService;
import com.etc.utils.PageData;

@RequestMapping(value="userapi")
@Controller
public class FoodsController {
	
	@Resource
	private FoodsService foodsService;
	
	@RequestMapping("showfoodsbyriu/{rid}")
	public String showFoodsByRid(@PathVariable("rid") Integer rid,Integer page,Integer limit,Model model) {
		if(page==null) {
			page=1;
		}
		if(limit==null) {
			limit=9;
		}
		PageData<RFoods> pd = new PageData<>();
		List<RFoods> list = foodsService.getFoodsByPage(page,limit,rid);
		int counts=foodsService.getcount(rid);
		int totalpage=(counts/limit)+1;
		pd.setData(list);
		pd.setLimit(limit);
		pd.setPage(page);
		pd.setCount(totalpage);
		model.addAttribute("pd", pd);
		return "user/foods";
	}
}
